package com.huang.design.behavior.Responsibility.ext;

import java.util.ArrayList;
import java.util.List;

public class FilterChain implements Filter  {

    int current=0;


    List<Filter>  filterChain=new ArrayList<>();
    void addFilter(Filter filter){
        filterChain.add(filter);
    }

    @Override
    public void doFilter(Request request, Response response, FilterChain chain) {
        if(current<filterChain.size()){
            Filter filter = filterChain.get(current);
            //先加 在执行  （注意） 要不然永远是执行第一个
            current++;
            filter.doFilter(request,response,chain);


        }

    }
}
